from re import S
import unittest
from selenium import webdriver
import sys
sys.path.append(r'D:\NetWork\micro-member-ui-automation')

# 导入包
from selenium.webdriver.chrome.options import Options
from Base.base_page import BasePage
from data.Config import config
from util.Draw import LuckDraw

#不重复打开浏览器 
chrome_options=Options()
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
chrome_driver=r'C:\Users\Administrator\AppData\Local\Programs\Python\Python39\chromedriver.exe'
driver=webdriver.Chrome(chrome_driver,chrome_options=chrome_options)
#窗口最大化
# driver.maximize_window()
#browser = webdriver.Chrome()
#print(driver.title)
# driver = webdriver.Chrome()
xp = 'xpath'

class StoredManage(LuckDraw,BasePage,unittest.TestCase):
    #菜单点击不同的活动
    def StoredManage(self,Stored_type):
        self.click(xp,'//span[text()="储值管理"]/../..')
        if Stored_type  == '买满赠送' :
            self.click(xp,'//span[text()="买满赠送"]/../..')
        elif Stored_type == '积分兑换储值':
            self.click(xp,'//span[text()="积分兑换储值"]/../..')
        elif Stored_type == '批量充值':
            self.click(xp,'//span[text()="批量充值"]/../..')
        elif Stored_type == '线上拉新活动' :
            self.click(xp,'//span[text()="线上拉新活动"]/../..')
        elif Stored_type == '批量充值' :
            self.click(xp,'//span[text()="批量充值"]/../..')
        elif Stored_type == '添加推荐人' :
            self.click(xp,'//span[text()="添加推荐人"]/../..')
        elif Stored_type == '充值管理' :
            self.click(xp,'//span[text()="充值方案管理"]/../..')
        elif Stored_type == '卡密充值批次' :
            self.click(xp,'//span[text()="卡密充值批次"]/../..')
        else :
            print('输入活动类型不存在')


    #新建积分兑储值活动
    def New_PointsFos(self,points,storage,sorting):     # points积分  storage储值   sorting排序
        self.new()
        self.input(xp,'//input[@placeholder="请输入积分"]',points)      
        self.input(xp,'//input[@placeholder="请输入储值"]',storage)
        self.input(xp,'//input[@placeholder="请输入排序"]',sorting)
        self.click(xp,'//span[text()="确 定"]/..')
    
    #新建批量充值批次
    def BatchUp(self,name,rules):
        self.new()
        self.input(xp,'//input[@placeholder="请输入批次名称"]',name)
        self.input(xp,'//input[@placeholder="请输入充值说明"]',rules)

    #批量充值列表
    def TopUpList(self,name,phone,amount):
        self.new()
        self.input(xp,'//input[@placeholder="请输入姓名"]',name)
        self.input(xp,'//input[@placeholder="请输入手机号"]',phone)
        self.input(xp,'//input[@placeholder="请输入充值金额"]',amount)
        self.click(xp,'//span[text()="确 定"]/..')

    #充值
    def TopUp(self,code):
        self.click(xp,'//span[text()="充值"]/..')
        self.click(xp,'//button[text()="获取验证码"]')
        self.input(xp,'//input[@placeholder="请输入密码"]',config.password)
        self.input(xp,'//input[@placeholder="请输入验证码"]',code)          #code通过键盘键入 code = input()

    #添加推荐人
    def AddReferees(self,name,phone):
        self.new()
        self.input(xp,'//input[@placeholder="请输入推荐人姓名"]',name)
        self.input(xp,'//input[@placeholder="请输入手机号"]',phone)
        self.click(xp,'//span[text()="确 定"]/..')

    #新建卡密充值批次
    def CamiloTopup(self,name,amount,num,begin,digits):
        self.click(xp,'//span[text()="添加"]/..')
        self.input(xp,'//input[@placeholder="请输入批次名称"]',name)    #批次名字
        self.input(xp,'//input[@placeholder="请输入金额"]',amount)      #金额
        self.input(xp,'//input[@placeholder="请输入数量"]',num)         #数量
        self.input(xp,'//input[@placeholder="请输入"]',begin)           #固定开头
        self.input(xp,'//input[@placeholder="请输入卡密位数"]',digits)      #卡密位数\
        self.click(xp,'//span[text()="保 存"]/..')

    #卡密导出
    def CamiloExport(self,code):
        self.click(xp,'//a[text()="导出"]')
        self.input(xp,'//input[@placeholder="请输入密码"]',config.password)
        self.input(xp,'//input[@placeholder="请输入验证码"]',code)          #code：短信验证码 通过键盘键入 code =input()        
        self.click(xp,'//span[text()="确 认"]/..')        

    #新增充值管理
    def Topupmanage(self,name,describe):
        self.click(xp,'//span[text()="添加"]/..')
        self.input(xp,'//input[@placeholder="请输入方案名称"]',name)
        self.input(xp,'//input[@placeholder="请输入方案描述"]',describe)

    #充值奖励
    def TopupOptions(self,gradientNuw,awradNuw,AS):   #gradientNuw 梯度数量 awradNuw奖励数量  AS梯度位数
        choos = '(//div[@class="item"])['+ AS +']'  #AS充值的梯度位数
        setting = choos + '/div/div/div[2]/div/div[3]'         #设置优惠路径
        add = choos + '/div/div/div[2]/div[1]/div'            #添加梯度路径
        addreward = choos + '/div[2]/div/div/div/div[3]/div'           #每梯度添加奖励路径
        #循环点击设置充值梯度，以及每个梯度下奖励数量
        for b in range(gradientNuw):
            self.click(xp,add)
            self.click(xp,setting)
            for c in range(awradNuw):
                self.click(addreward)
                c += 1 
            b += 1 

    #奖项填写
    def AwardFilIn(self,itemAS,rewarad,amount,type,Num,condition,limit,vouchers,Stime,Etime):      #vouchers 选择券和抽奖活动的名称
        amountPath = '(//span[text()="元"])'+ itemAS +'/..'  #充值金额路径
        rewaradPath = '(//div[@class="benefit"])['+ rewarad +']'    #奖励行数
        typePath = rewaradPath + '/div/div/div/div/div/span/div/div/div'  #类型路径
        NumPath = rewaradPath + '/div/div/div/div/div/span/span/span/input' #输入储值积分的数量路径
        conditionPath = rewaradPath + '/div/div/div/div[2]/div/span/div/div/div'   #条件路径        
        limitPath = rewaradPath + '/div/div/div[4]/div/div/span/input'  #限领次数路径
        
        self.input(xp,amountPath,amount)   #输入充值金额
        self.click(xp,typePath)     #选择类型
        self.TypeChoose(type,NumPath,Num,rewaradPath)   #类型判断
        self.Prizelist(type,vouchers)   #选择优惠券和抽奖机会
        self.input(xp,limitPath,limit)       #输入限领次数

        #选择领取条件-----
        self.click(xp,conditionPath)       #点击条件奖励
        #判断领取条件
        if condition == '首充值':
            self.click(xp,'//li[normalize-space(text())="首充值"]')
        elif condition == '时间段':
            self.click(xp,'//li[normalize-space(text())="时间段"]')
            self.choosetime(xp,Stime,Etime)  #时间控件 选时间
        else:
            pass

    #买满
    def Buyfull(self,name,relus,stime,etime,scope,iscontains,):   #scope:适用范围类型,iscontains:包含特价商品
        self.new()
        self.input(xp,'//input[@placeholder="营销名称"]',name)
        self.input(xp,'//input[@placeholder="营销描述"]',relus)
        stattime =  '//td[@title="'+stime +'"]'    #组合开始时间
        endtime = '//td[@title="'+etime +'"]'       #组合结束时间
        self.click(xp,'//input[@placeholder="开始日期"]')
        self.click(xp,stattime)           
        self.click(xp,endtime)
        scopePath = '//span[normalize-space(text())="'+ scope +'"]'
        self.click(xp,scopePath)
        self.click(xp,iscontains)
        

 

